<template>
	<view class="content">
		<view style="margin-top: 30rpx;" class="company-block">
			<image :src="info.logo?info.logo:imageUrl+'/job_hunting/job_detail/enterprise.jpg'"
				@error="onErrorImg(info)" class="company-photo"></image>
			<view class="company-info">
				<view class="company-item">
					<view class="company-name">{{info.name}}</view>
				</view>
				<view class="text" style="margin-top: 30rpx;">
					人力资源&nbsp;·&nbsp;{{info.scaleText||'暂无'}}
				</view>
			</view>
		</view>
		<view class="block dark aaum-block">
			<view class="title">机构介绍</view>
			<view class="info-item">
				<mp-html :content="info.introduce" />
			</view>
		</view>
		<view class="block dark image-block">
			<view class="title">机构证件</view>
			<view class="img-list">
				<view class="img-item" v-if="info.businessLicenseUrl">
					<image :src="info.businessLicenseUrl" @click="showBigImg(info.businessLicenseUrl)" class="img">
					</image>
					<view class="img-title">营业执照</view>
				</view>
				<view class="img-item" v-if="info.permitUrl">
					<image :src="info.permitUrl" @click="showBigImg(info.permitUrl)" class="img"></image>
					<view class="img-title">经营许可证</view>
				</view>
				<view class="img-item" v-if="info.laborDispatchUrl">
					<image :src="info.laborDispatchUrl" @click="showBigImg(info.laborDispatchUrl)" class="img"></image>
					<view class="img-title">劳务派遣证</view>
				</view>
				<view class="img-item" v-if="info.annualInspectionReportUrl">
					<image :src="info.annualInspectionReportUrl" @click="showBigImg(info.annualInspectionReportUrl)"
						class="img"></image>
					<view class="img-title">年检报告</view>
				</view>
				<view class="img-item" v-if="info.otherUrl">
					<image :src="info.otherUrl" @click="showBigImg(info.otherUrl)" class="img"></image>
					<view class="img-title">其他证件</view>
				</view>
			</view>
		</view>
		<view class="block dark adreess-block">
			<view class="title">机构地址</view>
			<view class="address">
				<view style="display: flex;align-items: center; width: calc(100% - 180rpx);">
					<view class="iconfont icon-dingwei"></view>
					<view class="address-content">{{info.address}}</view>
				</view>
				<view @click="openLocation"
					style="width: 160rpx;height: 70rpx;border: 1px solid #0256FF;border-radius: 60rpx;display: flex;align-items: center;justify-content: center;">
					<i style="color: #0256FF;font-size: 30rpx; margin-right: 10rpx;"
						class="iconfont icon-xitong-weizhipeizhi"></i>
					<view style="font-size: 30rpx;color: #0256FF;">地图</view>
				</view>
			</view>
		</view>
		<view class="block dark adreess-block">
			<view class="title">联系方式</view>
			<view class="address">
				<view style="display: flex;align-items: center; width: calc(100% - 200rpx);">
					<view class="iconfont icon-a-24gf-telephone2"></view>
					<view class="address-content">{{info.desensitizationMobile}}</view>
				</view>
				<view @click="callPhone"
					style="width: 160rpx;height: 70rpx;border: 1px solid #0256FF;border-radius: 60rpx;display: flex;align-items: center;justify-content: center;">
					<i style="color: #0256FF;font-size: 30rpx; margin-right: 10rpx;"
						class="iconfont icon-dianhuatianchong"></i>
					<view style="font-size: 30rpx;color: #0256FF;">拨打</view>
				</view>
			</view>
		</view>
		<view class="title">合作公司</view>
		<template v-if="list.length>0">
			<view style="margin-top: 30rpx;padding: 30rpx;" class="block dark company-block" v-for="item in list"
				@click="navigate('/page_other/company/company?id='+item.id)">
				<image :src="item.logoUrl?item.logoUrl:imageUrl+'/job_hunting/job_detail/enterprise.jpg'"
					class="company-photo"></image>
				<view class="company-info">
					<view class="company-item">
						<view class="company-name">{{item.brandName}}</view>
					</view>
					<view class="text" style="margin-top: 20rpx;">
						{{item.enterpriseTypeText||'暂无'}}&nbsp;·&nbsp;{{item.scaleName||'暂无'}}
					</view>
					<view style="display: flex;flex-direction: row; margin-top: 16rpx;">
						<view class="icon-item"
							style="display: flex;flex-direction: row; margin-right: 20rpx;align-items: center;">
							<view class="iconfont icon-AK-MN_dunpai_fill"
								style="color: #F9B04A; font-size: 36rpx;font-weight: bold;margin-top: 10rpx;"></view>
							<view class="text" style="font-size: 24rpx;">已认证营业执照</view>
						</view>
						<view class="icon-item" style="display: flex;flex-direction: row;align-items: center;">
							<view class="iconfont icon-AK-MN_dunpai_fill"
								style="color: #F9B04A;font-weight: bold;margin-top: 10rpx;">
							</view>
							<view class="text" style="font-size: 24rpx;">已认证手机号</view>
						</view>
					</view>
				</view>
			</view>
		</template>
		<view v-if="list.length==total&&!more" style="text-align: center;">没有更多了哦</view>
		<view v-else style="text-align: center;">暂无数据</view>
	</view>
</template>

<script>
	import {
		getSwiperList as getSwiperListApi
	} from '@/api/static.js'
	import {
		insertLookMe,
		getIntermediaryByIdApi
	} from '@/api/job_hunting.js'
	import {
		isMore
	} from '@/util/util.js'
	export default {

		data() {
			return {
				id: 0,
				info: {
					name: '',
					logo: '',
					scale: '',
					address: '',
					welfare: '',
					introduce: '',
					phone: '',
					recap: '',
					estDate: '',
				},
				list: [],
				latitude: 39.803382,
				longitude: 98.571037,
				page: 1,
				limit: 10,
				more: true,
				total: 0,
			}
		},
		onPullDownRefresh() {
			this.refresh();
			uni.stopPullDownRefresh();
		},
		onReachBottom() {
			if (this.more) {
				this.page++;
				this.getIntermediaryById()
			}
		},
		methods: {
			//onShareAppMessage 分享给朋友
			//onShareTimeline  分享到朋友圈
			// #ifdef MP
			onShareAppMessage: function(res) {
				if (res.from === 'button') {
					// 来自页面内转发按钮
					console.log(res.target)
				}
				return {
					title: this.info.name,
					path: '/page_other/company/company?id=' + this.id
				}
			},
			//点击放大图片
			showBigImg(imgsArray) {
				let arr = [];
				arr.push(imgsArray)
				uni.previewImage({
					current: 0,
					urls: arr //必须是网址路径，否则加载不出来，如：http：或https：
				});
			},
			// #endif
			onShareTimeline(res) {
				let distSource = uni.getStorageSync('distSource');
				if (distSource) {
					return {
						title: this.info.name,
						path: '/page_other/company/company?id=' + this.id,
						type: 0,
						query: 'id=' + distSource,
					}
				}
			},
			onErrorImg(item) {
				this.$set(item, 'logoUrl', this.imageUrl + '/job_hunting/job_detail/enterprise.jpg');
			},
			openLocation() {
				uni.openLocation({
					latitude: this.info.latitude,
					longitude: this.info.longitude,
					name: this.info.name,
					success: function() {
						console.log('success');
					}
				});
			},
			callPhone() {
				let para = {
					cancelText: '我再想想',
					success: (confirm) => {
						if (confirm.confirm) {
							uni.makePhoneCall({
								phoneNumber: this.info.mobile,
								success() {
									console.log('拨打成功了');
								},
								fail() {
									console.log('拨打失败了');
								}
							})
						}
					}
				}
				para.title = '确认拨打';
				para.content = '平台严禁用人单位做出任何损害求职者合法权益的违法违规行为，包括但不限于扣押求职者证件、收取求职者财物、向求职者集资、让求职者入股等，您一旦发现此类行为，请立即进行举报！'
				para.confirmText = '拨打';
				uni.showModal(para);

			},
			navigate(url) {
				uni.navigateTo({
					url
				})
			},
			refresh() {
				this.page = 1
				this.more = true
				this.getIntermediaryById(true);
			},
			getIntermediaryById(refresh = false) {
				getIntermediaryByIdApi({
					id: this.id,
					type: 1,
					page: this.page,
					limit: this.limit
				}).then((res) => {
					this.info = res;
					this.latitude = res.latitude;
					this.longitude = res.longitude;
					let list = res.enterpriseVo.list ?? [];
					this.list = refresh ? list : [...this.list, ...list],
						this.total = res.enterpriseVo.count
					this.more = isMore(this.page, this.limit, this.total)
				}).catch((res) => {
					console.log(3333333333333)
					console.log(res)
					this.showToast('机构信息不存在', function() {
						uni.navigateBack({})
					})
				})
			},
			addLookMe() {
				uni.showLoading({
					title: '关注中'
				})
				insertLookMe({
					eid: this.id,
					userType: 1,
					lookMeType: 2,
					state: 2
				}).then((res) => {
					uni.hideLoading();
					this.showDialog = true;
					this.getCompanyInfo();
				}).catch(() => {
					console.log(res)
				})
			},
			insertLookMe() {
				uni.showLoading({
					title: '取消关注中'
				})
				insertLookMe({
					eid: this.id,
					userType: 1,
					lookMeType: 2,
					state: 1
				}).then((res) => {
					uni.hideLoading();
					uni.showToast({
						title: '取消关注成功',
						icon: 'success'
					});
					this.getCompanyInfo();
				}).catch(() => {
					console.log(res)
				})
			},
			lookMe() {
				if (this.user) {
					insertLookMe({
						eid: this.id,
						userType: 1,
						lookMeType: 1,
						state: 2
					}).then((res) => {}).catch(() => {
						console.log(res)
					})
				}
			},
		},
		computed: {
			user() {
				return this.$store.getters.user
			}
		},
		onLoad(e) {
			this.id = e.id;
			this.imageUrl = this.globalConfig.imageUrl;
			this.getIntermediaryById();
			this.lookMe()
		}
	}
</script>

<style lang="scss">
	page {
		background: #F7F6F9;
	}

	.content {
		width: 100%;
		padding: 30rpx;

		.block {
			width: 100%;
			display: flex;
			flex-direction: row;
			margin-bottom: 30rpx;
		}

		.company-block {
			width: 100%;
			display: flex;
			flex-direction: row;
			margin-bottom: 30rpx;
			align-items: center;

			.company-photo {
				width: 150rpx;
				height: 150rpx;
				border-radius: 20rpx;
				flex-grow: 0;
				background-color: #fff;
			}

			.company-info {
				width: calc(100% - 160rpx);
				display: flex;
				flex-direction: column;
				margin-left: 20rpx;

				.company-item {
					width: 100%;
					display: flex;
					flex-direction: row;

					.company-name {
						width: calc(100% - 150rpx);
						font-size: 34rpx;
						font-weight: bold;
						margin-right: 40rpx;
					}

					.attention {
						margin-top: 10rpx;
						width: 120rpx;
						height: 45rpx;
						background: #0356FE;
						color: #fff;
						border-radius: 20rpx;
						text-align: center;
						font-size: 30rpx;
					}

					.attention1 {
						margin-top: 10rpx;
						width: 120rpx;
						height: 45rpx;
						background: none;
						color: #0356FE;
						border: 2rpx solid #0356FE;
						border-radius: 20rpx;
						text-align: center;
						font-size: 30rpx;
					}
				}

				.text {
					margin-top: 10rpx;
					font-size: 26rpx;
					color: #999;
				}

				.form-label {
					display: flex;
					margin-top: 20rpx;

					.form-title-label {
						font-size: 12px;
						color: #fff;
						//background-color: #CCDDFF;
						border: 1rpx solid #fff;
						width: 120rpx;
						height: 40rpx;
						border-radius: 10rpx;
						text-align: center;
						padding-top: 3rpx;
						margin-right: 20rpx;
					}
				}

				.other {
					margin-top: 10rpx;
					font-size: 26rpx;
					color: #999;
				}
			}
		}

		.block.dark {
			background: #fff;
			border-radius: 20rpx;
		}

		.block.adreess-block {
			width: 100%;
			display: flex;
			flex-direction: column;
			padding: 30rpx;

			.title {
				font-size: 34rpx;
				font-weight: bold;
			}

			.address {
				font-size: 28rpx;
				display: flex;
				flex-direction: row;
				align-items: center;
				margin-top: 20rpx;
				justify-content: space-between;

				.iconfont {
					flex-grow: 0;
					color: #999;
					margin-right: 10rpx;
				}

				.address-content {
					flex-grow: 1;
					overflow: hidden;
					text-overflow: ellipsis;
					white-space: nowrap;
				}

				.arrow {
					flex-grow: 0;
					font-size: 24rpx;
				}
			}
		}

		.title {
			font-size: 34rpx;
			font-weight: bold;
		}

		.aaum-block {
			margin-top: 30rpx;
			padding: 30rpx;
			font-size: 28rpx;
			display: flex;
			flex-direction: column;

			.info-item {
				width: 100%;
				padding: 10rpx 0;
				overflow: hidden;
				text-overflow: ellipsis;
				// white-space: nowrap;
			}

			.info-list {
				display: flex;
				flex-direction: row;

				.info-title {
					padding: 10rpx 0;
					overflow: hidden;
					text-overflow: ellipsis;
					font-size: 32rpx;
					font-weight: bold;
					flex-grow: 1;
				}

				.info-money {
					padding: 10rpx 0;
					font-size: 32rpx;
					font-weight: bold;
				}
			}
		}

		.image-block {
			margin-top: 30rpx;
			padding: 30rpx;
			font-size: 28rpx;
			display: flex;
			flex-direction: column;

			.img-list {
				display: flex;
				flex-wrap: wrap;

				.img-item:nth-child(3n) {
					margin-right: 0;
				}

				.img-item {
					display: flex;
					flex-direction: column;
					width: calc((100% - 60rpx) / 3);
					display: flex;
					margin-right: 30rpx;
					align-items: center;
					margin-top: 30rpx;

					.img {
						width: 100%;
						height: 160rpx;
						background: #F7F6F9;
						border-radius: 20rpx;
						margin-bottom: 10rpx;
					}
				}
			}
		}
	}
</style>